package com.zc.custom;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.zc.pojo.Staff;

import java.io.IOException;

/**
 * @description:
 * @author: cong
 * @create: 2025/2/19
 */
public class StaffSerializer extends JsonSerializer<Staff> {
    @Override
    public void serialize(Staff staff, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        jsonGenerator.writeStartObject();
        jsonGenerator.writeNumberField("id", staff.getId());
        jsonGenerator.writeStringField("name", staff.getName());
        jsonGenerator.writeNumberField("age", staff.getAge());
        jsonGenerator.writeNumberField("salary", staff.getSalary());
        jsonGenerator.writeArrayFieldStart("hobby");

    }
}
